//
//  loginIVew.m
//  NuanMao
//
//  Created by 绿水 on 16/2/24.
//  Copyright © 2016年 MJ. All rights reserved.
//

#import "loginIVew.h"

#define KleftWidth 10
#define KTopHeight (64+20)
#define KLaleHeight 44
#define KTextFiledLable 20//textFiled与lable间隔

typedef NS_ENUM(NSInteger,textFieledTag){
    //textFiledTag值
    KNanmeTFtg = 10,
    KPasswordTag,
};

@interface loginIVew ()<UITableViewDataSource,UITableViewDelegate>
{
    CGRect _rect;//屏幕尺寸
    UITableView *_tabelView;
}


@end

@implementation loginIVew

-(void)dealloc
{
    
    NSLog(@"loginView ==%s",__FUNCTION__);
}

- (void)viewDidLoad {
    [super viewDidLoad];


    self.automaticallyAdjustsScrollViewInsets = NO;
    _rect = [UIScreen mainScreen].bounds;
    
    _tabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, _rect.size.width, _rect.size.height-64) style:UITableViewStyleGrouped];
    _tabelView.dataSource = self;
    _tabelView.delegate = self;
    _tabelView.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1];
    [self.view addSubview:_tabelView];
    
    
    //注册按钮
    [self registerBtn];
    
    //添加手势
    [self addTapGesture];

}

#pragma mark - 单击手势

-(void)addTapGesture{
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapRecognizer:)];

    [_tabelView addGestureRecognizer:tap];
    
}
#pragma mark - 手势方法
-(void)tapRecognizer:(UITapGestureRecognizer *)reconzier
{
        _nameFiled = (UITextField *)[self.view viewWithTag:KNanmeTFtg];
    
        _passWordFiled = (UITextField *)[self.view viewWithTag:KPasswordTag];
    
    
    [_nameFiled endEditing:YES];
    [_passWordFiled endEditing:YES];
}


#pragma mark - 注册按钮忘记密码

-(void)registerBtn
{
    for(int i = 0; i < 2 ; i ++)
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        NSString *btntitle = i ==0 ? @"木有账号?戳我注册!":@"忘记密码";
        UIColor *btncolor = i == 0? [UIColor blackColor]: [UIColor redColor];
        [btn setTitle:btntitle forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:12];
        [btn setTitleColor:btncolor forState:UIControlStateNormal];
        btn.titleLabel.alpha = 0.65;
        btn.frame = CGRectMake((i+1)*_rect.size.width/3.0, 44*3, _rect.size.width/3.0, 20);
        [_tabelView addSubview:btn];
    }
}

#pragma mark - tableView协议
#pragma mark 必选协议

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

#pragma mark - 单元格重用
#pragma mark - 单元配置及textFiled
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        
            UILabel *lable = [[UILabel alloc]init];
            NSString *lableText = indexPath.row == 0 ? @"用户名":@"密    码";
            CGRect rectLable = [lableText boundingRectWithSize:CGSizeMake(MAXFLOAT, 44) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
            lable.frame = CGRectMake(KleftWidth, 0, rectLable.size.width+10, KLaleHeight);
            lable.text = lableText;
            [cell.contentView addSubview:lable];
            
        
            UITextField *textFiled = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(lable.frame) + KTextFiledLable, 0, _rect.size.width - CGRectGetMaxX(lable.frame) -KTextFiledLable, KLaleHeight)];
        if (indexPath.row == 0) {
            textFiled.tag = KNanmeTFtg;
        }
        else
        {
            textFiled.tag = KPasswordTag;
        }
            NSString *filedText = indexPath.row ==0 ? @"请输入用户名":@"请输入密码";
            textFiled.placeholder = filedText;
            [cell.contentView addSubview:textFiled];
        
    }
    return cell;
}



@end
